package com.web.dao;

import com.web.entity.CycleRegister;

import static org.apache.ibatis.jdbc.SqlBuilder.*;
import static org.apache.ibatis.jdbc.SqlBuilder.ORDER_BY;

/**
 * @author FDjavaone
 */
public class CycleRegisterSqlProvider {

    public String insertSelective(CycleRegister record) {
        BEGIN();
        INSERT_INTO("t_cycle_register");

        if (record.getmId() != null) {
            VALUES("m_id", "#{mId,jdbcType=BIGINT}");
        }

        if (record.getPhone() != null) {
            VALUES("phone", "#{phone,jdbcType=VARCHAR}");
        }

        if (record.getPassword() != null) {
            VALUES("password", "#{password,jdbcType=VARCHAR}");
        }

        if (record.getStatus() != null) {
            VALUES("status", "#{status,jdbcType=INTEGER}");
        }

        if (record.getCreateTime() != null) {
            VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }

        if (record.getModifyTime() != null) {
            VALUES("modify_time", "#{modifyTime,jdbcType=TIMESTAMP}");
        }

        return SQL();
    }

    public String updateByPrimaryKeySelective(CycleRegister record) {
        BEGIN();
        UPDATE("t_cycle_register");

        if (record.getmId() != null) {
            SET("m_id = #{mId,jdbcType=BIGINT}");
        }

        if (record.getPhone() != null) {
            SET("phone = #{phone,jdbcType=VARCHAR}");
        }

        if (record.getPassword() != null) {
            SET("password = #{password,jdbcType=VARCHAR}");
        }

        if (record.getStatus() != null) {
            SET("status = #{status,jdbcType=INTEGER}");
        }

        if (record.getCreateTime() != null) {
            SET("create_time = #{createTime,jdbcType=TIMESTAMP}");
        }

        if (record.getModifyTime() != null) {
            SET("modify_time = #{modifyTime,jdbcType=TIMESTAMP}");
        }

        WHERE("id = #{id,jdbcType=BIGINT}");

        return SQL();
    }

    public String selectUnRegister() {

        BEGIN();
        SELECT("tm.*");
        FROM("t_member tm ");
        LEFT_OUTER_JOIN(" t_cycle_register tc on tm.id=tc.m_id ");
        WHERE("tc.m_id is null ");
        return SQL();
    }

    public String selectNeedChangePassword() {

        BEGIN();
        SELECT("tm.*");
        FROM("t_member tm ");
        INNER_JOIN(" t_cycle_register tc on tm.id=tc.m_id ");
        WHERE("tc.password!=tm.password ");
        return SQL();
    }


}